package org.marlin.http.filter;

import org.marlin.http.http.Parameter;
import org.marlin.http.server.HttpServerUtil;
import org.marlin.http.server.ServerBean;

import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;


/**
 * init version 1.5.0
 * @author Jack ZG
 * @since 1.0.0
 */
public class ServerFilter
        extends HttpFilter {
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        try {
            HttpServletRequest request = (HttpServletRequest) servletRequest;
            String servletPath = request.getRequestURI();
            ServerBean serverBean = HttpServerUtil.getHttpServer(servletPath);
            Parameter[] parameters1 = HttpServerUtil.getParamters(servletPath);
            Parameter[] parameters2 = HttpServerUtil.getParamters(servletPath);


            serverBean.setParamNames(parameters1);
            serverBean.setParamNames(parameters2);
            Object object = serverBean.invoke();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

